{% extends 'layouts/master-page.html' %}
{% block title %}Admin page{% endblock %}
{% block head %}
<!-- css -->
<link href="/static/css/custom/admin.css" rel="stylesheet" />

<!-- javascript -->
<script type="text/javascript" src="/static/js/custom/admin.js"></script>
{% endblock %}
{% block content %}
{% include 'subpages/breadcrumbs.html' %}
<div class="row admin_row">
  <div class="col-md-3">
    <div class="card">
      <div class="card-header">
        <strong>Database info <b>{{stats['stats']['dbName']}}</b></strong>
      </div>
      <div class="card-body">
        <table class="table table-hover table-striped admin_table">
          <thead class="thead-dark">
          <tr class="warning"><th>Collection</th><th>#records</th><th>Last update</th></tr>
          </thead>
          <tbody>
          <tr><td>CVES</td>      <td>{{stats['data']['cves']['size']}}    </td>
            <td>{% if stats['data']['cves']['last_update']     is not none %} {{stats['data']['cves']['last_update'].strftime('%d-%m-%Y - %H:%M')}}     {% else %}Not updated{% endif %}</td><tr>
          <tr><td>CPE</td>       <td>{{stats['data']['cpe']['size']}}     </td>
            <td>{% if stats['data']['cpe']['last_update']      is not none %} {{stats['data']['cpe']['last_update'].strftime('%d-%m-%Y - %H:%M')}}      {% else %}Not updated{% endif %}</td><tr>
          <tr><td>CPE-other</td> <td>{{stats['data']['cpeOther']['size']}}</td>
            <td>{% if stats['data']['cpeOther']['last_update'] is not none %} {{stats['data']['cpeOther']['last_update'].strftime('%d-%m-%Y - %H:%M')}} {% else %}Not updated{% endif %}</td><tr>
          <tr><td>Capec</td>     <td>{{stats['data']['capec']['size']}}   </td>
            <td>{% if stats['data']['capec']['last_update']    is not none %} {{stats['data']['capec']['last_update'].strftime('%d-%m-%Y - %H:%M')}}    {% else %}Not updated{% endif %}</td><tr>
          <tr><td>CWE</td>       <td>{{stats['data']['cwe']['size']}}     </td>
            <td>{% if stats['data']['cwe']['last_update']      is not none %} {{stats['data']['cwe']['last_update'].strftime('%d-%m-%Y - %H:%M')}}      {% else %}Not updated{% endif %}</td><tr>
          <tr><td>via4</td>      <td>{{stats['data']['via4']['size']}}    </td>
            <td>{% if stats['data']['via4']['last_update']     is not none %} {{stats['data']['via4']['last_update'].strftime('%d-%m-%Y - %H:%M')}}     {% else %}Not updated{% endif %}</td><tr>
          </tbody>
        </table>
        <span id="wl_rules">Whitelist: {{stats['data']['whitelist']['size']}} rules</span><br />
        <span id="bl_rules">Blacklist: {{stats['data']['blacklist']['size']}} rules</span><br /><br />
        <span>Database size: {{'%0.2f' % (stats['stats']['db_size']/1024**2)}}MB ({{'%0.2f' % (stats['stats']['db_size']/1024**3)}}GB)</span><br />
        <span>Database size on disk: {{'%0.2f' % (stats['stats']['size_on_disk']/1024**2)}}MB ({{'%0.2f' % (stats['stats']['size_on_disk']/1024**3)}}GB)</span>
      </div>
    </div>
  </div>
  <div class="col-md-3">
    <!-- Change password -->
    <div class="card">
      <div class="card-header">
        <strong>Change your password</strong>
      </div>
      <div class="card-body">
        <table class="admin_table">
          <tr><td class="passwd_td">Current</td><td><input type="password" class="form-control" name="current_pass" id="current_pass"></td></tr>
          <tr><td class="passwd_td">New    </td><td><input type="password" class="form-control" name="new_pass"     id="new_pass">    </td></tr>
          <tr><td class="passwd_td">Repeat </td><td><input type="password" class="form-control" name="repeat_pass"  id="repeat_pass"> </td></tr>
        </table>
        <button class="btn btn-success btn-sm" onclick="changePass()">Update</button>
      </div>
    </div>
    <!-- Database update -->
    <div class="card">
      <div class="card-header">
        <strong>Update the database</strong>
      </div>
      <div class="card-body">
        <button class="btn btn-primary btn-sm" onclick="updateDB()" class="margin_left">Update</button>
      </div>
    </div>
  </div>
  <div class="col-md-3">
    <!-- Whitelist import -->
    <div class="card">
      <div class="card-header">
        <strong>Manage whitelist</strong>
      </div>
      <div class="card-body">
        <input class="form-control-file" id="wl_Import" type='file' name='file' /> <br />
        <input class="form-check-input margin-left-null" type="checkbox" id="wl_ForceImport">
        <label class="form-check-label margin-left margin-bottom" for="wl_ForceImport">Force</label> <br />
        <button class="btn btn-warning btn-sm" onclick="whitelistImport()">Import</button>
        <button class="btn btn-warning btn-sm" onclick="whitelistExport()">Export</button>
        <button class="btn btn-danger btn-sm" onclick="dropWhitelist()">Drop list</button>
        <button class="btn btn-success btn-sm" onclick="location.href='/admin/whitelist'">View</button>
      </div>
    </div>
    <!-- Blacklist import -->
    <div class="card">
      <div class="card-header">
        <strong>Manage blacklist</strong>
      </div>
      <div class="card-body">
        <input class="form-control-file" id="bl_Import" type='file' name='file' /> <br />
        <input class="form-check-input margin-left-null" type="checkbox" id="bl_ForceImport">
        <label class="form-check-label margin-left margin-bottom" for="bl_ForceImport">Force</label> <br />
        <button class="btn btn-warning btn-sm" onclick="blacklistImport()">Import</button>
        <button class="btn btn-warning btn-sm" onclick="blacklistExport()">Export</button>
        <button class="btn btn-danger btn-sm" onclick="dropBlacklist()">Drop list</button>
        <button class="btn btn-success btn-sm" onclick="location.href='/admin/blacklist'">View</button>
      </div>
    </div>
  </div>
  <div class="col-md-3">
    <!-- Plug-in information -->
    <div class="card">
      <div class="card-header">
        <strong>Plug-in Information</strong>
      </div>
      <div class="card-body">
        <table class="table table-hover table-striped admin_table">
          <thead class="thead-dark">
          <tr class="warning"><th>Name</th><th>UID</th><th>Type</th><th>State</th></tr>
          </thead>
          <tbody>
          {% for plug in plugins|sort(attribute="name") %}
          {% set ptype = "Web" if plug.isWebPlugin() else "Backend" %}
          <tr><td>{{plug.name}}</td><td>{{plug.uid}}</td><td>{{ptype}}</td><td>{{plug.loadstate}}</td></tr>
          {% endfor %}
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>

{% endblock %}
{% block body_scripts %}
<script>
	$(document).ready(function(){
		parseStatus('{{status}}')
	});
</script>
{% endblock %}